﻿using Xunit;

namespace dogd.Tests
{
	public class SqlStatementCacheFacts
	{
		public class TheFindMethod
		{
			[Fact]
			public void ReturnsTheStatementIfItIsInTheCache()
			{
				var cache = new SqlStatementCache();

				cache.Add(typeof(SqlStatementCacheFacts), "Select * from Table", CrudOption.Select);

				string sql = cache.Find(typeof(SqlStatementCacheFacts), CrudOption.Select);

				Assert.Equal("Select * from Table", sql);
			}
		}

		public class TheAddMethod
		{
			[Fact]
			public void ReplacesExistingTextInTheCacheForTheSameTypeAndCrudOption()
			{
				var cache = new SqlStatementCache();

				cache.Add(typeof(SqlStatementCacheFacts), "Select * from Table", CrudOption.Select);
				cache.Add(typeof(SqlStatementCacheFacts), "Delete from Table", CrudOption.Select);

				string sql = cache.Find(typeof(SqlStatementCacheFacts), CrudOption.Select);

				Assert.Equal("Delete from Table", sql);
			}
		}
	}
}
